﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Diagnostics;
using System.IO;



[assembly: log4net.Config.XmlConfigurator( ConfigFile="logging.config")]
[assembly: log4net.Config.Repository]
namespace Syk.Library.Log
{
    [DebuggerStepThrough]
    public class Logger
    {
        private static volatile Logger m_Logger;
        private static readonly object m_SyncRoot = new object();

        private Logger()  { }

        public static Logger Instance
        {
            get
            {
                if (m_Logger == null)
                {
                    lock (m_SyncRoot)
                    {
                        if (m_Logger == null)
                        {
                            m_Logger = new Logger();
                        }
                    }
                }

                return m_Logger;
            }
        }

        private string MessageBuilder(string message, params object[] args)
        {
            return string.Format(message, args);
        }

        public void Fatal(string category, string message, params object[] args)
        {
            LogManager.GetLogger(category).Fatal(MessageBuilder(message, args));
        }

        public void Error(string category, string message, params object[] args)
        {
            LogManager.GetLogger(category).Error(MessageBuilder(message, args));
        }

        public void Fatal(string category, Exception ex)
        {
            LogManager.GetLogger(category).Fatal(ex.ToString());
        }

        public void Error(string category, Exception ex)
        {
            LogManager.GetLogger(category).Error(ex.ToString());
        }

        public void Error(string category, string message, Exception ex)
        {
            LogManager.GetLogger(category).Error(MessageBuilder("{0} : {1}", message, ex));
        }

        public void Warn(string category, string message, params object[] args)
        {
            LogManager.GetLogger(category).Warn(MessageBuilder(message, args));
        }

        public void Info(string category, string message, params object[] args)
        {
            LogManager.GetLogger(category).Info(MessageBuilder(message, args));
        }

        public void Debug(string category, string message, params object[] args)
        {
            LogManager.GetLogger(category).Debug(MessageBuilder(message, args));
        }

    }
}

